//
// Created by francklinson on 2021/11/24 AT 11:17.
// May Saint Diana bless you!
//

#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>

using namespace std;

class Solution {
public:
    bool rotateString(string s, string goal) {
        int m = s.size(), n = goal.size();
        //  首先长度要一样
        if (m != n)
            return false;
        // 逐次移位
        for (int i = 0; i < m; ++i) {
            if (s == goal)
                return true;
            s.push_back(s[0]);
            s.erase(0, 1);
        }
        return false;
    }

    bool rotateString2(string s, string goal) {
        int ns = s.size(), ng = goal.size();
        if (ns != ng) return false;
        if (s == goal) return true;
        for (int i = 1; i < ns; i++) {
            if (s[i] != goal[0]) continue;
            bool isMatch = true;
            for (int j = 0; j < ns; j++)
                if (s[(i + j) % ns] != goal[j]) {  // 不实际移动
                    isMatch = false;
                    break;
                }
            if (isMatch) return true;
        }
        return false;
    }

    bool rotateString3(string s, string goal) {
        return s.size() == goal.size() && (s + s).find(goal) != string::npos;
    }
};

int main() {
    Solution solution;
    cout << solution.rotateString3("abcde", "cdeab") << endl;
    cout << solution.rotateString3("abcde", "abced") << endl;
    return 0;
}

